package org.example.shopping;

import org.example.goods.Goods;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class ShoppingCart {

    private Map<Goods,BigDecimal> shopGoods = new HashMap();


    //添加购买商品
    public void addGoodsToShoppingCart(BigDecimal weight, Goods goods){
        //记录购买的商品
        shopGoods.put(goods,weight);

    }
    // 获取购买商品的总价
    public BigDecimal getTotalPrice() {
        BigDecimal totalPrice = new BigDecimal("0");
        for (Goods goods : shopGoods.keySet()) {
            BigDecimal weight = shopGoods.get(goods);
            totalPrice = totalPrice.add(weight.multiply(goods.getPrice()).multiply(goods.getDiscount()));
        }
        return totalPrice;
    }

    // 清空购物车
    public void resetCart() {
        shopGoods.clear();
    }

}
